//
//  ViewController.m
//  MapNav
//
//  Created by  Mac on 2017/9/17.
//  Copyright © 2017年  Mac. All rights reserved.
//

#import "ViewController.h"


#define SAVEDEFAULTS(value,key) [[NSUserDefaults standardUserDefaults] setObject:value forKey:key];\
[[NSUserDefaults standardUserDefaults] synchronize];

#define GETDEFAULTS(key) [[NSUserDefaults standardUserDefaults] objectForKey:key];


#import <AMapFoundationKit/AMapFoundationKit.h>

#import <AMapSearchKit/AMapSearchKit.h>

@interface ViewController ()<AMapNaviDriveManagerDelegate,AMapNaviDriveViewDelegate,AMapSearchDelegate>

@property (nonatomic, strong) AMapNaviPoint *startPoint;
@property (nonatomic, strong) AMapNaviPoint *endPoint;
@property(nonatomic,strong) NSTimer * timer;

@property(nonatomic,strong)AMapSearchAPI * search;

@property(nonatomic,strong)MAPointAnnotation * startAnnotation;
@property(nonatomic,strong)MAPointAnnotation * destinationAnnotation;

@end

@implementation ViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    [self.view setBackgroundColor:[UIColor whiteColor]];
    
    
    [self initDriveView];
    
    [self initDriveManager];
    
    
    UIButton * button = [UIButton buttonWithType:(UIButtonTypeCustom)];
    button.frame = CGRectMake(0, 0, 120, 40);
    //    button.backgroundColor = [UIColor whiteColor];
    button.layer.borderWidth = 1;
    button.layer.masksToBounds = YES;
    button.layer.borderColor = [UIColor blueColor].CGColor;
    
    button.layer.cornerRadius = 5;
    [button setTitle:@"路线规划方案" forState:(UIControlStateNormal)];
    [button setTitleColor:[UIColor blueColor] forState:(UIControlStateNormal)];
    [button addTarget:self action:@selector(clickBtnFunction) forControlEvents:(UIControlEventTouchUpInside)];
    [button setTitleColor:[UIColor lightGrayColor] forState:(UIControlStateHighlighted)];
//    [self.view addSubview:button];
    
    UIBarButtonItem * item = [[UIBarButtonItem alloc]initWithCustomView:button];
    self.navigationItem.rightBarButtonItem = item;
    
//    [self initProperties];
    
//    113.810414,23.297576 鸡母冚
//    113.788377,23.274528 华商职业学院
//    113.827328,23.210048   增江大桥
    AMapNaviPoint * pointStart = [[AMapNaviPoint alloc] init];
    pointStart.latitude = 23.297576;
    pointStart.longitude = 113.810414;
    self.startPoint = pointStart;
    
    AMapNaviPoint * pointEnd = [[AMapNaviPoint alloc] init];
    pointEnd.latitude = 23.210048;
    pointEnd.longitude = 113.827328;
    self.endPoint = pointEnd;
    
    

    
    self.search = [[AMapSearchAPI alloc] init];
    self.search.delegate = self;
    
    
    self.startAnnotation.coordinate = CLLocationCoordinate2DMake(23.297576, 113.810414);
    self.destinationAnnotation.coordinate = CLLocationCoordinate2DMake(23.210048, 113.827328);
    
    
    
    UIButton * button1 = [UIButton buttonWithType:(UIButtonTypeCustom)];
    button1.frame = CGRectMake(10, 65, 120, 40);
    //    button.backgroundColor = [UIColor whiteColor];
    button1.layer.borderWidth = 1;
    button1.layer.masksToBounds = YES;
    button1.layer.borderColor = [UIColor blueColor].CGColor;
    
    button1.layer.cornerRadius = 5;
    [button1 setTitle:@"导航方案" forState:(UIControlStateNormal)];
    [button1 setTitleColor:[UIColor blueColor] forState:(UIControlStateNormal)];
    [button1 addTarget:self action:@selector(clickBtnFunction2) forControlEvents:(UIControlEventTouchUpInside)];
    [button1 setTitleColor:[UIColor lightGrayColor] forState:(UIControlStateHighlighted)];
    [self.view addSubview:button1];
    
    UIBarButtonItem * item2 = [[UIBarButtonItem alloc]initWithCustomView:button1];
    self.navigationItem.leftBarButtonItem = item2;
    
}


-(void)clickBtnFunction2
{
 
   
    
    UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"导航方案" message:nil preferredStyle:UIAlertControllerStyleAlert];
    
    [alert addAction:[UIAlertAction actionWithTitle:@"方案1" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
      
        
        AMapDrivingRouteSearchRequest *navi = [[AMapDrivingRouteSearchRequest alloc] init];
        
        navi.requireExtension = YES;
          navi.strategy = 1;
        /* 出发点. */
        navi.origin = [AMapGeoPoint locationWithLatitude:self.startAnnotation.coordinate.latitude
                                               longitude:self.startAnnotation.coordinate.longitude];
        
        /* 目的地. */
        navi.destination = [AMapGeoPoint locationWithLatitude:self.destinationAnnotation.coordinate.latitude
                                                    longitude:self.destinationAnnotation.coordinate.longitude];
        
        [self.driveManager calculateDriveRouteWithEndPoints:@[self.endPoint] wayPoints:nil drivingStrategy:0];
        
        //         ConvertDrivingPreferenceToDrivingStrategy(NO,YES,YES,YES,NO);
        
        [self.search AMapDrivingRouteSearch:navi];

        
        
    }]];
    [alert addAction:[UIAlertAction actionWithTitle:@"方案2" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        
        
        AMapDrivingRouteSearchRequest *navi = [[AMapDrivingRouteSearchRequest alloc] init];
        
        navi.requireExtension = YES;
        navi.strategy = 2;
        /* 出发点. */
        navi.origin = [AMapGeoPoint locationWithLatitude:self.startAnnotation.coordinate.latitude
                                               longitude:self.startAnnotation.coordinate.longitude];
        
        /* 目的地. */
        navi.destination = [AMapGeoPoint locationWithLatitude:self.destinationAnnotation.coordinate.latitude
                                                    longitude:self.destinationAnnotation.coordinate.longitude];
        
        [self.driveManager calculateDriveRouteWithEndPoints:@[self.endPoint] wayPoints:nil drivingStrategy:0];
        
        //         ConvertDrivingPreferenceToDrivingStrategy(NO,YES,YES,YES,NO);
        
        [self.search AMapDrivingRouteSearch:navi];
        
        
        
    }]];
    [alert addAction:[UIAlertAction actionWithTitle:@"方案3" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        
        
        AMapDrivingRouteSearchRequest *navi = [[AMapDrivingRouteSearchRequest alloc] init];
        
        navi.requireExtension = YES;
        navi.strategy = 3;
        /* 出发点. */
        navi.origin = [AMapGeoPoint locationWithLatitude:self.startAnnotation.coordinate.latitude
                                               longitude:self.startAnnotation.coordinate.longitude];
        
        /* 目的地. */
        navi.destination = [AMapGeoPoint locationWithLatitude:self.destinationAnnotation.coordinate.latitude
                                                    longitude:self.destinationAnnotation.coordinate.longitude];
        
        [self.driveManager calculateDriveRouteWithEndPoints:@[self.endPoint] wayPoints:nil drivingStrategy:0];
        
        //         ConvertDrivingPreferenceToDrivingStrategy(NO,YES,YES,YES,NO);
        
        [self.search AMapDrivingRouteSearch:navi];
        
        
        
    }]];
    [alert addAction:[UIAlertAction actionWithTitle:@"方案4" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        
        
        AMapDrivingRouteSearchRequest *navi = [[AMapDrivingRouteSearchRequest alloc] init];
        
        navi.requireExtension = YES;
        navi.strategy = 4;
        /* 出发点. */
        navi.origin = [AMapGeoPoint locationWithLatitude:self.startAnnotation.coordinate.latitude
                                               longitude:self.startAnnotation.coordinate.longitude];
        
        /* 目的地. */
        navi.destination = [AMapGeoPoint locationWithLatitude:self.destinationAnnotation.coordinate.latitude
                                                    longitude:self.destinationAnnotation.coordinate.longitude];
        
        [self.driveManager calculateDriveRouteWithEndPoints:@[self.endPoint] wayPoints:nil drivingStrategy:0];
        
        //         ConvertDrivingPreferenceToDrivingStrategy(NO,YES,YES,YES,NO);
        
        [self.search AMapDrivingRouteSearch:navi];
        
        
        
    }]];
    [alert addAction:[UIAlertAction actionWithTitle:@"方案5" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        
        
        AMapDrivingRouteSearchRequest *navi = [[AMapDrivingRouteSearchRequest alloc] init];
        
        navi.requireExtension = YES;
        navi.strategy = 5;
        /* 出发点. */
        navi.origin = [AMapGeoPoint locationWithLatitude:self.startAnnotation.coordinate.latitude
                                               longitude:self.startAnnotation.coordinate.longitude];
        
        /* 目的地. */
        navi.destination = [AMapGeoPoint locationWithLatitude:self.destinationAnnotation.coordinate.latitude
                                                    longitude:self.destinationAnnotation.coordinate.longitude];
        
        [self.driveManager calculateDriveRouteWithEndPoints:@[self.endPoint] wayPoints:nil drivingStrategy:0];
        
        //         ConvertDrivingPreferenceToDrivingStrategy(NO,YES,YES,YES,NO);
        
        [self.search AMapDrivingRouteSearch:navi];
        
        
        
    }]];
    [alert addAction:[UIAlertAction actionWithTitle:@"方案6" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        
        
        AMapDrivingRouteSearchRequest *navi = [[AMapDrivingRouteSearchRequest alloc] init];
        
        navi.requireExtension = YES;
        navi.strategy = 6;
        /* 出发点. */
        navi.origin = [AMapGeoPoint locationWithLatitude:self.startAnnotation.coordinate.latitude
                                               longitude:self.startAnnotation.coordinate.longitude];
        
        /* 目的地. */
        navi.destination = [AMapGeoPoint locationWithLatitude:self.destinationAnnotation.coordinate.latitude
                                                    longitude:self.destinationAnnotation.coordinate.longitude];
        
        [self.driveManager calculateDriveRouteWithEndPoints:@[self.endPoint] wayPoints:nil drivingStrategy:0];
        
        //         ConvertDrivingPreferenceToDrivingStrategy(NO,YES,YES,YES,NO);
        
        [self.search AMapDrivingRouteSearch:navi];
        
        
        
    }]];
    [alert addAction:[UIAlertAction actionWithTitle:@"方案7" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        
        
        AMapDrivingRouteSearchRequest *navi = [[AMapDrivingRouteSearchRequest alloc] init];
        
        navi.requireExtension = YES;
        navi.strategy = 7;
        /* 出发点. */
        navi.origin = [AMapGeoPoint locationWithLatitude:self.startAnnotation.coordinate.latitude
                                               longitude:self.startAnnotation.coordinate.longitude];
        
        /* 目的地. */
        navi.destination = [AMapGeoPoint locationWithLatitude:self.destinationAnnotation.coordinate.latitude
                                                    longitude:self.destinationAnnotation.coordinate.longitude];
        
        [self.driveManager calculateDriveRouteWithEndPoints:@[self.endPoint] wayPoints:nil drivingStrategy:0];
        
        //         ConvertDrivingPreferenceToDrivingStrategy(NO,YES,YES,YES,NO);
        
        [self.search AMapDrivingRouteSearch:navi];
        
        
        
    }]];
    [alert addAction:[UIAlertAction actionWithTitle:@"方案8" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        
        
        AMapDrivingRouteSearchRequest *navi = [[AMapDrivingRouteSearchRequest alloc] init];
        
        navi.requireExtension = YES;
        navi.strategy = 8;
        /* 出发点. */
        navi.origin = [AMapGeoPoint locationWithLatitude:self.startAnnotation.coordinate.latitude
                                               longitude:self.startAnnotation.coordinate.longitude];
        
        /* 目的地. */
        navi.destination = [AMapGeoPoint locationWithLatitude:self.destinationAnnotation.coordinate.latitude
                                                    longitude:self.destinationAnnotation.coordinate.longitude];
        
        [self.driveManager calculateDriveRouteWithEndPoints:@[self.endPoint] wayPoints:nil drivingStrategy:0];
        
        //         ConvertDrivingPreferenceToDrivingStrategy(NO,YES,YES,YES,NO);
        
        [self.search AMapDrivingRouteSearch:navi];
        
        
        
    }]];
    [alert addAction:[UIAlertAction actionWithTitle:@"方案9" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        
        
        AMapDrivingRouteSearchRequest *navi = [[AMapDrivingRouteSearchRequest alloc] init];
        
        navi.requireExtension = YES;
        navi.strategy = 9;
        /* 出发点. */
        navi.origin = [AMapGeoPoint locationWithLatitude:self.startAnnotation.coordinate.latitude
                                               longitude:self.startAnnotation.coordinate.longitude];
        
        /* 目的地. */
        navi.destination = [AMapGeoPoint locationWithLatitude:self.destinationAnnotation.coordinate.latitude
                                                    longitude:self.destinationAnnotation.coordinate.longitude];
        
        [self.driveManager calculateDriveRouteWithEndPoints:@[self.endPoint] wayPoints:nil drivingStrategy:0];
        
        //         ConvertDrivingPreferenceToDrivingStrategy(NO,YES,YES,YES,NO);
        
        [self.search AMapDrivingRouteSearch:navi];
        
        
        
    }]];

    
    
    
    [self presentViewController:alert animated:YES completion:nil];

    
}


-(void)clickBtnFunction
{

    UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"路线规划方案" message:nil preferredStyle:UIAlertControllerStyleAlert];
    
    [alert addAction:[UIAlertAction actionWithTitle:@"方案0" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        
        
        
        AMapDrivingRouteSearchRequest *navi = [[AMapDrivingRouteSearchRequest alloc] init];
        
        navi.requireExtension = YES;
//        navi.strategy = 1;
        /* 出发点. */
        navi.origin = [AMapGeoPoint locationWithLatitude:self.startAnnotation.coordinate.latitude
                                               longitude:self.startAnnotation.coordinate.longitude];
        
        /* 目的地. */
        navi.destination = [AMapGeoPoint locationWithLatitude:self.destinationAnnotation.coordinate.latitude
                                                    longitude:self.destinationAnnotation.coordinate.longitude];
        
          [self.driveManager calculateDriveRouteWithEndPoints:@[self.endPoint] wayPoints:nil drivingStrategy:0];
        
//         ConvertDrivingPreferenceToDrivingStrategy(NO,YES,YES,YES,NO);
        
        [self.search AMapDrivingRouteSearch:navi];

    }]];
    
    
    
    [alert addAction:[UIAlertAction actionWithTitle:@"方案1" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        
        
        
        AMapDrivingRouteSearchRequest *navi = [[AMapDrivingRouteSearchRequest alloc] init];
        
        navi.requireExtension = YES;
//        navi.strategy = 1;
        /* 出发点. */
        navi.origin = [AMapGeoPoint locationWithLatitude:self.startAnnotation.coordinate.latitude
                                               longitude:self.startAnnotation.coordinate.longitude];
        
        /* 目的地. */
        navi.destination = [AMapGeoPoint locationWithLatitude:self.destinationAnnotation.coordinate.latitude
                                                    longitude:self.destinationAnnotation.coordinate.longitude];
        
        
        
        
        [self.driveManager calculateDriveRouteWithEndPoints:@[self.endPoint] wayPoints:nil drivingStrategy:1];
        
        //         ConvertDrivingPreferenceToDrivingStrategy(NO,YES,YES,YES,NO);
        
        [self.search AMapDrivingRouteSearch:navi];
        
    }]];

    [alert addAction:[UIAlertAction actionWithTitle:@"方案2" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        
        
        
        AMapDrivingRouteSearchRequest *navi = [[AMapDrivingRouteSearchRequest alloc] init];
        
        navi.requireExtension = YES;
        navi.strategy = 1;
        /* 出发点. */
        navi.origin = [AMapGeoPoint locationWithLatitude:self.startAnnotation.coordinate.latitude
                                               longitude:self.startAnnotation.coordinate.longitude];
        
        /* 目的地. */
        navi.destination = [AMapGeoPoint locationWithLatitude:self.destinationAnnotation.coordinate.latitude
                                                    longitude:self.destinationAnnotation.coordinate.longitude];
        
        
        
        
        [self.driveManager calculateDriveRouteWithEndPoints:@[self.endPoint] wayPoints:nil drivingStrategy:2];
        
        //         ConvertDrivingPreferenceToDrivingStrategy(NO,YES,YES,YES,NO);
        
        [self.search AMapDrivingRouteSearch:navi];
        
    }]];

    [alert addAction:[UIAlertAction actionWithTitle:@"方案3" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        
        
        
        AMapDrivingRouteSearchRequest *navi = [[AMapDrivingRouteSearchRequest alloc] init];
        
        navi.requireExtension = YES;
        navi.strategy = 1;
        /* 出发点. */
        navi.origin = [AMapGeoPoint locationWithLatitude:self.startAnnotation.coordinate.latitude
                                               longitude:self.startAnnotation.coordinate.longitude];
        
        /* 目的地. */
        navi.destination = [AMapGeoPoint locationWithLatitude:self.destinationAnnotation.coordinate.latitude
                                                    longitude:self.destinationAnnotation.coordinate.longitude];
        
        
        
        
        [self.driveManager calculateDriveRouteWithEndPoints:@[self.endPoint] wayPoints:nil drivingStrategy:3];
        
        //         ConvertDrivingPreferenceToDrivingStrategy(NO,YES,YES,YES,NO);
        
        [self.search AMapDrivingRouteSearch:navi];
        
    }]];

    [alert addAction:[UIAlertAction actionWithTitle:@"方案4" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        
        
        
        AMapDrivingRouteSearchRequest *navi = [[AMapDrivingRouteSearchRequest alloc] init];
        
        navi.requireExtension = YES;
//        navi.strategy = 1;
        /* 出发点. */
        navi.origin = [AMapGeoPoint locationWithLatitude:self.startAnnotation.coordinate.latitude
                                               longitude:self.startAnnotation.coordinate.longitude];
        
        /* 目的地. */
        navi.destination = [AMapGeoPoint locationWithLatitude:self.destinationAnnotation.coordinate.latitude
                                                    longitude:self.destinationAnnotation.coordinate.longitude];
        
        
        
        
        [self.driveManager calculateDriveRouteWithEndPoints:@[self.endPoint] wayPoints:nil drivingStrategy:4];
        
        //         ConvertDrivingPreferenceToDrivingStrategy(NO,YES,YES,YES,NO);
        
        [self.search AMapDrivingRouteSearch:navi];
        
    }]];

    [alert addAction:[UIAlertAction actionWithTitle:@"方案5" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        
        
        
        AMapDrivingRouteSearchRequest *navi = [[AMapDrivingRouteSearchRequest alloc] init];
        
        navi.requireExtension = YES;
//        navi.strategy = 1;
        /* 出发点. */
        navi.origin = [AMapGeoPoint locationWithLatitude:self.startAnnotation.coordinate.latitude
                                               longitude:self.startAnnotation.coordinate.longitude];
        
        /* 目的地. */
        navi.destination = [AMapGeoPoint locationWithLatitude:self.destinationAnnotation.coordinate.latitude
                                                    longitude:self.destinationAnnotation.coordinate.longitude];
        
        
        
        
        [self.driveManager calculateDriveRouteWithEndPoints:@[self.endPoint] wayPoints:nil drivingStrategy:5];
        
        //         ConvertDrivingPreferenceToDrivingStrategy(NO,YES,YES,YES,NO);
        
        [self.search AMapDrivingRouteSearch:navi];
        
    }]];

    [alert addAction:[UIAlertAction actionWithTitle:@"方案6" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        
        
        
        AMapDrivingRouteSearchRequest *navi = [[AMapDrivingRouteSearchRequest alloc] init];
        
        navi.requireExtension = YES;
//        navi.strategy = 1;
        /* 出发点. */
        navi.origin = [AMapGeoPoint locationWithLatitude:self.startAnnotation.coordinate.latitude
                                               longitude:self.startAnnotation.coordinate.longitude];
        
        /* 目的地. */
        navi.destination = [AMapGeoPoint locationWithLatitude:self.destinationAnnotation.coordinate.latitude
                                                    longitude:self.destinationAnnotation.coordinate.longitude];
        
        
        
        
        [self.driveManager calculateDriveRouteWithEndPoints:@[self.endPoint] wayPoints:nil drivingStrategy:6];
        
        //         ConvertDrivingPreferenceToDrivingStrategy(NO,YES,YES,YES,NO);
        
        [self.search AMapDrivingRouteSearch:navi];
        
    }]];

    [alert addAction:[UIAlertAction actionWithTitle:@"方案7" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        
        
        
        AMapDrivingRouteSearchRequest *navi = [[AMapDrivingRouteSearchRequest alloc] init];
        
        navi.requireExtension = YES;
        navi.strategy = 1;
        /* 出发点. */
        navi.origin = [AMapGeoPoint locationWithLatitude:self.startAnnotation.coordinate.latitude
                                               longitude:self.startAnnotation.coordinate.longitude];
        
        /* 目的地. */
        navi.destination = [AMapGeoPoint locationWithLatitude:self.destinationAnnotation.coordinate.latitude
                                                    longitude:self.destinationAnnotation.coordinate.longitude];
        
        
        
        
        [self.driveManager calculateDriveRouteWithEndPoints:@[self.endPoint] wayPoints:nil drivingStrategy:7];
        
        //         ConvertDrivingPreferenceToDrivingStrategy(NO,YES,YES,YES,NO);
        
        [self.search AMapDrivingRouteSearch:navi];
        
    }]];

    [alert addAction:[UIAlertAction actionWithTitle:@"方案8" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        
        
        
        AMapDrivingRouteSearchRequest *navi = [[AMapDrivingRouteSearchRequest alloc] init];
        
        navi.requireExtension = YES;
        navi.strategy = 1;
        /* 出发点. */
        navi.origin = [AMapGeoPoint locationWithLatitude:self.startAnnotation.coordinate.latitude
                                               longitude:self.startAnnotation.coordinate.longitude];
        
        /* 目的地. */
        navi.destination = [AMapGeoPoint locationWithLatitude:self.destinationAnnotation.coordinate.latitude
                                                    longitude:self.destinationAnnotation.coordinate.longitude];
        
        
        
        
        [self.driveManager calculateDriveRouteWithEndPoints:@[self.endPoint] wayPoints:nil drivingStrategy:8];
        
        //         ConvertDrivingPreferenceToDrivingStrategy(NO,YES,YES,YES,NO);
        
        [self.search AMapDrivingRouteSearch:navi];
        
    }]];

    [alert addAction:[UIAlertAction actionWithTitle:@"方案9" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        
        
        
        AMapDrivingRouteSearchRequest *navi = [[AMapDrivingRouteSearchRequest alloc] init];
        
        navi.requireExtension = YES;
        navi.strategy = 1;
        /* 出发点. */
        navi.origin = [AMapGeoPoint locationWithLatitude:self.startAnnotation.coordinate.latitude
                                               longitude:self.startAnnotation.coordinate.longitude];
        
        /* 目的地. */
        navi.destination = [AMapGeoPoint locationWithLatitude:self.destinationAnnotation.coordinate.latitude
                                                    longitude:self.destinationAnnotation.coordinate.longitude];
        
        
        
        
        [self.driveManager calculateDriveRouteWithEndPoints:@[self.endPoint] wayPoints:nil drivingStrategy:9];
        
        //         ConvertDrivingPreferenceToDrivingStrategy(NO,YES,YES,YES,NO);
        
        [self.search AMapDrivingRouteSearch:navi];
        
    }]];

    [alert addAction:[UIAlertAction actionWithTitle:@"方案10" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        
        
        
        AMapDrivingRouteSearchRequest *navi = [[AMapDrivingRouteSearchRequest alloc] init];
        
        navi.requireExtension = YES;
//        navi.strategy = 1;
        /* 出发点. */
        navi.origin = [AMapGeoPoint locationWithLatitude:self.startAnnotation.coordinate.latitude
                                               longitude:self.startAnnotation.coordinate.longitude];
        
        /* 目的地. */
        navi.destination = [AMapGeoPoint locationWithLatitude:self.destinationAnnotation.coordinate.latitude
                                                    longitude:self.destinationAnnotation.coordinate.longitude];
        
        
        
        
        [self.driveManager calculateDriveRouteWithEndPoints:@[self.endPoint] wayPoints:nil drivingStrategy:10];
        
        //         ConvertDrivingPreferenceToDrivingStrategy(NO,YES,YES,YES,NO);
        
        [self.search AMapDrivingRouteSearch:navi];
        
    }]];

    [alert addAction:[UIAlertAction actionWithTitle:@"方案11" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        
        
        
        AMapDrivingRouteSearchRequest *navi = [[AMapDrivingRouteSearchRequest alloc] init];
        
        navi.requireExtension = YES;
//        navi.strategy = 1;
        /* 出发点. */
        navi.origin = [AMapGeoPoint locationWithLatitude:self.startAnnotation.coordinate.latitude
                                               longitude:self.startAnnotation.coordinate.longitude];
        
        /* 目的地. */
        navi.destination = [AMapGeoPoint locationWithLatitude:self.destinationAnnotation.coordinate.latitude
                                                    longitude:self.destinationAnnotation.coordinate.longitude];
        
        
        
        
        [self.driveManager calculateDriveRouteWithEndPoints:@[self.endPoint] wayPoints:nil drivingStrategy:11];
        
        //         ConvertDrivingPreferenceToDrivingStrategy(NO,YES,YES,YES,NO);
        
        [self.search AMapDrivingRouteSearch:navi];
        
    }]];

    [alert addAction:[UIAlertAction actionWithTitle:@"方案12" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        
        
        
        AMapDrivingRouteSearchRequest *navi = [[AMapDrivingRouteSearchRequest alloc] init];
        
        navi.requireExtension = YES;
//        navi.strategy = 1;
        /* 出发点. */
        navi.origin = [AMapGeoPoint locationWithLatitude:self.startAnnotation.coordinate.latitude
                                               longitude:self.startAnnotation.coordinate.longitude];
        
        /* 目的地. */
        navi.destination = [AMapGeoPoint locationWithLatitude:self.destinationAnnotation.coordinate.latitude
                                                    longitude:self.destinationAnnotation.coordinate.longitude];
        
        
        
        
        [self.driveManager calculateDriveRouteWithEndPoints:@[self.endPoint] wayPoints:nil drivingStrategy:12];
        
        //         ConvertDrivingPreferenceToDrivingStrategy(NO,YES,YES,YES,NO);
        
        [self.search AMapDrivingRouteSearch:navi];
        
    }]];

    [alert addAction:[UIAlertAction actionWithTitle:@"方案13" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        
        
        
        AMapDrivingRouteSearchRequest *navi = [[AMapDrivingRouteSearchRequest alloc] init];
        
        navi.requireExtension = YES;
//        navi.strategy = 1;
        /* 出发点. */
        navi.origin = [AMapGeoPoint locationWithLatitude:self.startAnnotation.coordinate.latitude
                                               longitude:self.startAnnotation.coordinate.longitude];
        
        /* 目的地. */
        navi.destination = [AMapGeoPoint locationWithLatitude:self.destinationAnnotation.coordinate.latitude
                                                    longitude:self.destinationAnnotation.coordinate.longitude];
        
        
        
        
        [self.driveManager calculateDriveRouteWithEndPoints:@[self.endPoint] wayPoints:nil drivingStrategy:13];
        
        //         ConvertDrivingPreferenceToDrivingStrategy(NO,YES,YES,YES,NO);
        
        [self.search AMapDrivingRouteSearch:navi];
        
    }]];

    [alert addAction:[UIAlertAction actionWithTitle:@"方案14" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        
        
        
        AMapDrivingRouteSearchRequest *navi = [[AMapDrivingRouteSearchRequest alloc] init];
        
        navi.requireExtension = YES;
//        navi.strategy = 1;
        /* 出发点. */
        navi.origin = [AMapGeoPoint locationWithLatitude:self.startAnnotation.coordinate.latitude
                                               longitude:self.startAnnotation.coordinate.longitude];
        
        /* 目的地. */
        navi.destination = [AMapGeoPoint locationWithLatitude:self.destinationAnnotation.coordinate.latitude
                                                    longitude:self.destinationAnnotation.coordinate.longitude];
        
        
        
        
        [self.driveManager calculateDriveRouteWithEndPoints:@[self.endPoint] wayPoints:nil drivingStrategy:14];
        
        //         ConvertDrivingPreferenceToDrivingStrategy(NO,YES,YES,YES,NO);
        
        [self.search AMapDrivingRouteSearch:navi];
        
    }]];

    [alert addAction:[UIAlertAction actionWithTitle:@"方案15" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        
        
        
        AMapDrivingRouteSearchRequest *navi = [[AMapDrivingRouteSearchRequest alloc] init];
        
        navi.requireExtension = YES;
//        navi.strategy = 1;
        /* 出发点. */
        navi.origin = [AMapGeoPoint locationWithLatitude:self.startAnnotation.coordinate.latitude
                                               longitude:self.startAnnotation.coordinate.longitude];
        
        /* 目的地. */
        navi.destination = [AMapGeoPoint locationWithLatitude:self.destinationAnnotation.coordinate.latitude
                                                    longitude:self.destinationAnnotation.coordinate.longitude];
        
        
        
        
        [self.driveManager calculateDriveRouteWithEndPoints:@[self.endPoint] wayPoints:nil drivingStrategy:15];
        
        //         ConvertDrivingPreferenceToDrivingStrategy(NO,YES,YES,YES,NO);
        
        [self.search AMapDrivingRouteSearch:navi];
        
    }]];

    [alert addAction:[UIAlertAction actionWithTitle:@"方案16" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        
        
        
        AMapDrivingRouteSearchRequest *navi = [[AMapDrivingRouteSearchRequest alloc] init];
        
        navi.requireExtension = YES;
//        navi.strategy = 1;
        /* 出发点. */
        navi.origin = [AMapGeoPoint locationWithLatitude:self.startAnnotation.coordinate.latitude
                                               longitude:self.startAnnotation.coordinate.longitude];
        
        /* 目的地. */
        navi.destination = [AMapGeoPoint locationWithLatitude:self.destinationAnnotation.coordinate.latitude
                                                    longitude:self.destinationAnnotation.coordinate.longitude];
        
        
        
        
        [self.driveManager calculateDriveRouteWithEndPoints:@[self.endPoint] wayPoints:nil drivingStrategy:16];
        
        //         ConvertDrivingPreferenceToDrivingStrategy(NO,YES,YES,YES,NO);
        
        [self.search AMapDrivingRouteSearch:navi];
        
    }]];

    [alert addAction:[UIAlertAction actionWithTitle:@"方案17" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        
        
        
        AMapDrivingRouteSearchRequest *navi = [[AMapDrivingRouteSearchRequest alloc] init];
        
        navi.requireExtension = YES;
//        navi.strategy = 1;
        /* 出发点. */
        navi.origin = [AMapGeoPoint locationWithLatitude:self.startAnnotation.coordinate.latitude
                                               longitude:self.startAnnotation.coordinate.longitude];
        
        /* 目的地. */
        navi.destination = [AMapGeoPoint locationWithLatitude:self.destinationAnnotation.coordinate.latitude
                                                    longitude:self.destinationAnnotation.coordinate.longitude];
        
        
        
        
        [self.driveManager calculateDriveRouteWithEndPoints:@[self.endPoint] wayPoints:nil drivingStrategy:17];
        
        //         ConvertDrivingPreferenceToDrivingStrategy(NO,YES,YES,YES,NO);
        
        [self.search AMapDrivingRouteSearch:navi];
        
    }]];

    [alert addAction:[UIAlertAction actionWithTitle:@"方案18" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        
        
        
        AMapDrivingRouteSearchRequest *navi = [[AMapDrivingRouteSearchRequest alloc] init];
        
        navi.requireExtension = YES;
//        navi.strategy = 1;
        /* 出发点. */
        navi.origin = [AMapGeoPoint locationWithLatitude:self.startAnnotation.coordinate.latitude
                                               longitude:self.startAnnotation.coordinate.longitude];
        
        /* 目的地. */
        navi.destination = [AMapGeoPoint locationWithLatitude:self.destinationAnnotation.coordinate.latitude
                                                    longitude:self.destinationAnnotation.coordinate.longitude];
        
        
        
        
        [self.driveManager calculateDriveRouteWithEndPoints:@[self.endPoint] wayPoints:nil drivingStrategy:18];
        
        //         ConvertDrivingPreferenceToDrivingStrategy(NO,YES,YES,YES,NO);
        
        [self.search AMapDrivingRouteSearch:navi];
        
    }]];

    [alert addAction:[UIAlertAction actionWithTitle:@"方案19" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        
        
        
        AMapDrivingRouteSearchRequest *navi = [[AMapDrivingRouteSearchRequest alloc] init];
        
        navi.requireExtension = YES;
//        navi.strategy = 1;
        /* 出发点. */
        navi.origin = [AMapGeoPoint locationWithLatitude:self.startAnnotation.coordinate.latitude
                                               longitude:self.startAnnotation.coordinate.longitude];
        
        /* 目的地. */
        navi.destination = [AMapGeoPoint locationWithLatitude:self.destinationAnnotation.coordinate.latitude
                                                    longitude:self.destinationAnnotation.coordinate.longitude];
        
        
        
        
        [self.driveManager calculateDriveRouteWithEndPoints:@[self.endPoint] wayPoints:nil drivingStrategy:19];
        
        //         ConvertDrivingPreferenceToDrivingStrategy(NO,YES,YES,YES,NO);
        
        [self.search AMapDrivingRouteSearch:navi];
        
    }]];
    
    [alert addAction:[UIAlertAction actionWithTitle:@"方案20" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        
        
        
        AMapDrivingRouteSearchRequest *navi = [[AMapDrivingRouteSearchRequest alloc] init];
        
        navi.requireExtension = YES;
                navi.strategy = 1;
        /* 出发点. */
        navi.origin = [AMapGeoPoint locationWithLatitude:self.startAnnotation.coordinate.latitude
                                               longitude:self.startAnnotation.coordinate.longitude];
        
        /* 目的地. */
        navi.destination = [AMapGeoPoint locationWithLatitude:self.destinationAnnotation.coordinate.latitude
                                                    longitude:self.destinationAnnotation.coordinate.longitude];
        
        
        
        
        [self.driveManager calculateDriveRouteWithEndPoints:@[self.endPoint] wayPoints:nil drivingStrategy:20];
        
        //         ConvertDrivingPreferenceToDrivingStrategy(NO,YES,YES,YES,NO);
        
        [self.search AMapDrivingRouteSearch:navi];
        
    }]];

    
    
    [self presentViewController:alert animated:YES completion:nil];
    
}


- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    
//  self.navigationController.navigationBarHidden = YES;
    
    self.navigationController.toolbarHidden = YES;
    
//    _timer = [NSTimer scheduledTimerWithTimeInterval:5.0 target:self selector:@selector(RedisForUpLoadData) userInfo:nil repeats:YES];
//    // 把定时器添加到当前运行循环,并且调为通用模式
//    [[NSRunLoop currentRunLoop] addTimer:_timer forMode:NSRunLoopCommonModes];
    
    
    
    
}

-(void)RedisForUpLoadData
{
    NSLog(@"test for it");
}


- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
    
//    [self calculateRoute];
}
-(void)viewWillDisappear:(BOOL)animated
{
    [super viewWillAppear:animated];
    self.navigationController.navigationBarHidden = NO;
    self.navigationController.toolbarHidden = YES;
    self.driveManager = nil;
    self.driveView = nil;
    [_timer invalidate];
    _timer = nil;
    
}

- (void)viewWillLayoutSubviews
{
    UIInterfaceOrientation interfaceOrientation = [[UIApplication sharedApplication] statusBarOrientation];
    if ([[[UIDevice currentDevice] systemVersion] floatValue] < 8.0)
    {
        interfaceOrientation = self.interfaceOrientation;
    }
    
    if (UIInterfaceOrientationIsPortrait(interfaceOrientation))
    {
        [self.driveView setIsLandscape:NO];
    }
    else if (UIInterfaceOrientationIsLandscape(interfaceOrientation))
    {
        [self.driveView setIsLandscape:YES];
    }
}

-(void)dealloc
{
    [_timer invalidate];
    _timer = nil;
}

- (BOOL)prefersStatusBarHidden
{
    return YES;
}

#pragma mark - Initalization

//- (void)initProperties
//{
//    //为了方便展示,选择了固定的起终点
////    self.startPoint = [AMapNaviPoint locationWithLatitude:self.startPointLat longitude:self.startPointLon];
////    self.endPoint   = [AMapNaviPoint locationWithLatitude:self.endPointLat longitude:self.endPointLon];
////    NSLog(@"startPoint == %@ , endPoint == %@ ",self.startPoint,self.endPoint);
//}

- (void)initDriveManager
{
    if (self.driveManager == nil)
    {
        self.driveManager = [[AMapNaviDriveManager alloc] init];
        [self.driveManager setDelegate:self];
        
        [self.driveManager setAllowsBackgroundLocationUpdates:YES];
        
//       [self.driveManager setPausesLocationUpdatesAutomatically:NO];
        
//       将driveView添加为导航数据的Representative，使其可以接收到导航诱导数据
        
        [self.driveManager addDataRepresentative:self.driveView];
        
    }
}

- (void)initDriveView
{
    if (self.driveView == nil)
    {
        self.driveView = [[AMapNaviDriveView alloc] initWithFrame:self.view.bounds];
        self.driveView.autoresizingMask = UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight;
        self.driveView.trackingMode = AMapNaviViewTrackingModeCarNorth;
        [self.driveView setDelegate:self];
        [self.view addSubview:self.driveView];
    }
}



#pragma mark - Route Plan

- (void)calculateRoute
{
    //进行路径规划
//     [self.driveManager calculateDriveRouteWithStartPoints:@[self.startPoint]
//                                                    endPoints:@[self.endPoint]
//                                                    wayPoints:nil
//                                              drivingStrategy:AMapNaviDrivingStrategySingleDefault];
    [self.driveManager calculateDriveRouteWithEndPoints:@[self.endPoint] wayPoints:nil drivingStrategy:AMapNaviDrivingStrategySinglePrioritiseDistance];
    
}

#pragma mark - AMapNaviDriveManager Delegate

- (void)driveManager:(AMapNaviDriveManager *)driveManager error:(NSError *)error
{
    NSLog(@"error:{%ld - %@}", (long)error.code, error.localizedDescription);
}

- (void)driveManagerOnCalculateRouteSuccess:(AMapNaviDriveManager *)driveManager
{
    //    NSLog(@"onCalculateRouteSuccess");
    
    NSLog(@"距离 =  %ld",driveManager.naviRoute.routeLength);
    //算路成功后开始GPS导航
    [self.driveManager startGPSNavi];
}

- (void)driveManager:(AMapNaviDriveManager *)driveManager onCalculateRouteFailure:(NSError *)error
{
    //    NSLog(@"onCalculateRouteFailure:{%ld - %@}", (long)error.code, error.localizedDescription);
}

- (void)driveManager:(AMapNaviDriveManager *)driveManager didStartNavi:(AMapNaviMode)naviMode
{
    //    NSLog(@"didStartNavi");
}

- (void)driveManagerNeedRecalculateRouteForYaw:(AMapNaviDriveManager *)driveManager
{
    //    NSLog(@"needRecalculateRouteForYaw");
}

- (void)driveManagerNeedRecalculateRouteForTrafficJam:(AMapNaviDriveManager *)driveManager
{
    //    NSLog(@"needRecalculateRouteForTrafficJam");
}

- (void)driveManager:(AMapNaviDriveManager *)driveManager onArrivedWayPoint:(int)wayPointIndex
{
    //    NSLog(@"onArrivedWayPoint:%d", wayPointIndex);
}

//- (BOOL)driveManagerIsNaviSoundPlaying:(AMapNaviDriveManager *)driveManager
//{
////    return [[SpeechSynthesizer sharedSpeechSynthesizer] isSpeaking];
//}

- (void)driveManager:(AMapNaviDriveManager *)driveManager playNaviSoundString:(NSString *)soundString soundStringType:(AMapNaviSoundType)soundStringType
{
    //    NSLog(@"playNaviSoundString:{%ld:%@}", (long)soundStringType, soundString);
    
//    [[SpeechSynthesizer sharedSpeechSynthesizer] speakString:soundString];
}

- (void)driveManagerDidEndEmulatorNavi:(AMapNaviDriveManager *)driveManager
{
    //    NSLog(@"didEndEmulatorNavi");
}

- (void)driveManagerOnArrivedDestination:(AMapNaviDriveManager *)driveManager
{
    //    NSLog(@"onArrivedDestination");
}

#pragma mark - AMapNaviWalkViewDelegate

- (void)driveViewCloseButtonClicked:(AMapNaviDriveView *)driveView
{
    //停止导航
    [self.driveManager stopNavi];
    [self.driveManager removeDataRepresentative:self.driveView];
    
    //停止语音
//   [[SpeechSynthesizer sharedSpeechSynthesizer] stopSpeak];
    
     [self.navigationController popViewControllerAnimated:YES];
}


- (void)driveViewTrunIndicatorViewTapped:(AMapNaviDriveView *)driveView
{
    //    NSLog(@"TrunIndicatorViewTapped");
}

- (void)driveView:(AMapNaviDriveView *)driveView didChangeShowMode:(AMapNaviDriveViewShowMode)showMode
{
    //    NSLog(@"didChangeShowMode:%ld", (long)showMode);
}

#pragma mark - MoreMenu Delegate



- (void)moreMenuViewNightTypeChangeTo:(BOOL)isShowNightType
{
    [self.driveView setShowStandardNightType:isShowNightType];
}

- (void)moreMenuViewTrackingModeChangeTo:(AMapNaviViewTrackingMode)trackingMode
{
    [self.driveView setTrackingMode:trackingMode];
}


- (void)driveManager:(AMapNaviDriveManager *)driveManager updateNaviInfo:(nullable AMapNaviInfo *)naviInfo
{
    
 
    
}

- (void)driveManager:(AMapNaviDriveManager *)driveManager updateNaviLocation:(nullable AMapNaviLocation *)naviLocation
{
  
    
//    NSData * data = [NSKeyedArchiver archivedDataWithRootObject:naviLocation];
//    
//    NSString * str = [NSString stringWithFormat:@"%@",[self getCurrentTimeForSave]];
//    
//    NSDictionary * dict = [NSDictionary dictionaryWithObjectsAndKeys:data,@"data", str,@"time",nil];
//    
//    NSArray * array =  GETDEFAULTS(@"valueForSaveMessage")
//    
//    NSMutableArray * mutArray = [NSMutableArray arrayWithArray:array];
//    
//    [mutArray addObject:dict];
//    
//    SAVEDEFAULTS(mutArray, @"valueForSaveMessage")
    
    //    // 底部提示框
    //    UIAlertControllerStyleActionSheet
    //    // 中部提示框
    //    UIAlertControllerStyleAlert
    //    UIAlertActionStyleDefault, //默认
    //    UIAlertActionStyleCancel, //取消
    //    UIAlertActionStyleDestructive //警告
    
//  UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"注册新用户" message:nil preferredStyle:UIAlertControllerStyleAlert];
//    
//    
//    [alert addAction:[UIAlertAction actionWithTitle:@"收藏" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
//    }]];
//    
//    [self presentViewController:alert animated:YES completion:nil];
    
    
    
    
}


- (void)onRouteSearchDone:(AMapRouteSearchBaseRequest *)request response:(AMapRouteSearchResponse *)response
{
    if (response.route == nil)
    {
        return;
    }
    
    //解析response获取路径信息，具体解析见 Demo
    

    

}


- (void)AMapSearchRequest:(id)request didFailWithError:(NSError *)error
{
    NSLog(@"Error: %@", error);
}


-(NSString *)getCurrentTimeForSave
{
    
    NSDate *senddate = [NSDate date];
    NSDateFormatter *dateformatter = [[NSDateFormatter alloc] init];
    [dateformatter setDateFormat:@"YYYY-MM-dd HH:mm:ss"];
    NSString *date1 = [dateformatter stringFromDate:senddate];
    return date1;
    
}


@end
